<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_right">
          <div>
            <el-button icon="Back" @click="router.push({ name: 'module_business_product_list' })">
              {{ $t('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" stripe>
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" :label="i18n('common.id')" width="70">
          </el-table-column>

          <el-table-column :label="$t('product.resource.name')" min-width="150">

            <template v-slot="scope">
              <dl class="table_dl">
                <dt>
                  <el-image class="cx-list-image" :src="resource_url" loading="lazy" lazy>
                  </el-image>
                </dt>
                <dd class="table_dl_dd_all_30">
                  {{ scope.row.filename }}
                </dd>
                <dd class="table_dl_dd_all_16_gray">
                  {{ scope.row.create_time }}
                </dd>
              </dl>
            </template>
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="100">
            <template v-slot="scope">
              <el-button
                v-if="isAuth('module:business:product:resource:handle')"
                icon="Download"
                @click="downloadHandle(scope.row.url)">
                {{ i18n('product.resource.download') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="product-resource-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"
  import resource_url from "@/assets/images/default/resource.png"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('business/product/resource')

  const dataForm = reactive([
    'product_id',
  ])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    deleteHandle,
  } = useTable(model.value, dataForm)

  const downloadHandle = (url) => {
    window.open(url)
  }

  onMounted(() => {
    dataForm.product_id = query.product_id;

    getDataList(model)
  })
</script>
